package com.docMan.bean;

import java.io.File;
import java.io.IOException;

import com.docMan.lucene.Indexer;
import com.docMan.utils.DeleteFileService;
import com.docMan.utils.FinalConfig;

public class IndexRunnable implements Runnable {
	private IndexFile indexFile;
	private DeleteFileService deleteFileService = DeleteFileService
			.getInstance();

	public IndexRunnable(IndexFile indexFile) {
		this.indexFile = indexFile;
	}

	@Override
	public void run() {
		try {
			//Indexer indexer = new Indexer("d:\\lucene");
			Indexer indexer = Indexer.getInstance(FinalConfig.index_dir);
			File file = new File(indexFile.getFilePath());
			indexer.indexFile(file, indexFile.getFileId()+"",indexFile);
			deleteFileService.deleteFile(indexFile.getFilePath());
			indexer.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}

}
